package whf.framework.security.acegiimp;

import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpSessionEvent;

import org.acegisecurity.concurrent.SessionRegistry;
import org.springframework.beans.BeansException;

import whf.framework.log.Log;
import whf.framework.log.LogFactory;
import whf.framework.util.BeanFactory;

/**
 * 覆盖原有HttpSessionEventPublisher，提供将session从sessionRegistry中删除
 * @author king
 * @create 2008-1-31 上午10:01:14
 * 
 */
public class HttpSessionEventPublisher extends org.acegisecurity.ui.session.HttpSessionEventPublisher {
	private static final Log logger = LogFactory.getLog(HttpSessionEventPublisher.class);

	@Override
	public void sessionDestroyed(HttpSessionEvent event) {
		this.removeSessionRegistry(event);
		super.sessionDestroyed(event);
	}

	/**
	 * romove session in sessionRegistry
	 * @param event
	 */
	private void removeSessionRegistry(HttpSessionEvent event) {
		HttpSession session = event.getSession();
		try {
			SessionRegistry sessionRegistry = (SessionRegistry)BeanFactory.getBean("sessionRegistry");
			sessionRegistry.removeSessionInformation(session.getId());
		} catch (BeansException e) {
			logger.error("get SessionRegistry bean error,make sure bean name 'sessionRegistryImpl' exists", e);
		}
	}
}
